<cfcomponent>
	<cfset variables.TURBINE_PATH = reReplace(ExpandPath('./'),'(#application.env.context#[\\\.a-zA-Z0-9/_-]+)$','#application.env.context#', 'ALL') />

	<cffunction name="init">
		<cfreturn this />
	</cffunction>

	
	<cffunction access="public" returntype="String" name="getAvailableDSNs">
		<!--- get a list of DSNs in the current cf admin. --->
		<cfset dsnArray = CreateObject("java", "coldfusion.server.ServiceFactory").getDataSourceService().getNames() />
		<cfreturn arrayToList(dsnArray) />
	</cffunction>
	
	<cffunction access="public" returntype="String" name="getAvailableContexts" output="true">
		<!--- run a list of folders in this directory that are siblings of current dir --->
		<cfset current_context_path = rereplacenocase(variables.TURBINE_PATH,application.env.context,'','ALL') />	
		
		
		<cfdirectory action="list" directory="#current_context_path#" name="wwwFolderList" />
		<cfset availableContexts = "" />
		<cfloop query="wwwFolderList">
			<cfif type eq 'dir'>
				<cfset availableContexts = listAppend(availableContexts, "#name#") />
			</cfif>
		</cfloop>		
		<cfreturn availableContexts />
	</cffunction>

	<cffunction access="remote" returntype="String" name="getAvailableModels">
		<cfargument name="context_name" required="true" type="string" />
		<cfset var Model_List = "" />
		<cfset var context_path = "" />
		<cfset context_path = rereplacenocase(variables.TURBINE_PATH,application.env.context,arguments.context_name,'ALL') />	
		<!--- run a list of folders in this directory that are siblings of current dir --->
		<cfdirectory action="list" directory="#context_path#/app/model" name="ModelsFolder" />
		
		<cfloop query="ModelsFolder">
			<cfif not listContainsNoCase("base_model.cfc,model_factory.cfc",name)>
				<cfset Model_List = listAppend(Model_List, "#rereplace(name,'.cfc','','ALL')#") />
			</cfif>
		</cfloop>
		
		<cfreturn Model_List />
	</cffunction>
	
	<cffunction access="remote" returntype="String" name="getAvailableMigrations">
		<cfargument name="context_name" required="true" type="string" />
		<cfset var lst_migrations = "" />
		<cfset var context_path = "" /> 
		<cfset context_path = rereplacenocase(variables.TURBINE_PATH,application.env.context,arguments.context_name,'ALL') />	
		
		<cfdirectory action="list" directory="#context_path#/app/migrations" name="MigrationsQry" />
		
		<cfoutput query="MigrationsQry"><cfset lst_migrations=listAppend(lst_migrations,'{"db_migration_name":"#rereplace(name,'.cfc','','ALL')#"}') /></cfoutput>
		
		<cfreturn "[#lst_migrations#]" />
	</cffunction>
</cfcomponent>